<template>
	<view class="my-userinfo-container">
		<view class="top-box">
			<image :src="userinfo.avatarUrl" class="avatar"></image>
			<text class="nickname">{{userinfo.nickName}}</text>
		</view>
		<view class="panel-list">
			<view class="panel">
				<view class="panel-body">
					<view class="panel-item">
						<text class="number">00</text>
						<text class="title">收藏的店铺</text>
					</view>
					<view class="panel-item">
						<text class="number">00</text>
						<text class="title">收藏的商品</text>
					</view>
					<view class="panel-item">
						<text class="number">00</text>
						<text class="title">关注的商品</text>
					</view>
					<view class="panel-item">
						<text class="number">00</text>
						<text class="title">足迹</text>
					</view>
				</view>
			</view>
			<view class="panel">
				<view class="panel-title">我的订单</view>
				<view class="panel-body">
					<view class="panel-item">
						<image src="../../static/tabbar/page2.png" class="icon"></image>
						<text class="title">待付款</text>
					</view>
					<view class="panel-item">
						<image src="../../static/tabbar/page2.png" class="icon"></image>
						<text class="title">待收货</text>
					</view>
					<view class="panel-item">
						<image src="../../static/tabbar/page2.png" class="icon"></image>
						<text class="title">退款</text>
					</view>
					<view class="panel-item">
						<image src="../../static/tabbar/page2.png" class="icon"></image>
						<text class="title">退货</text>
					</view>
				</view>
			</view>
			<view class="panel">
				<view class="panel-list-item">
					<text class="title">收货地址</text>
					<uni-icons type="arrowright" size="15"></uni-icons>
				</view>
				<view class="panel-list-item">
					<text class="title">联系客服</text>
					<uni-icons type="arrowright" size="15"></uni-icons>
				</view>
				<view class="panel-list-item" @click="logout">
					<text class="title">退出登录</text>
					<uni-icons type="arrowright" size="15"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>

	import {mapState,mapMutations} from 'vuex'
	export default {
		name:"my-userinfo",
		data() {
			return {
				
			};
		},
		computed:{
			...mapState('m_user',['userinfo'])
		},
		methods:{
			...mapMutations('m_user',['updateAddress','updateUserinfo','updateToken']),
			
			// async logout() {
			// 	const [err, res] = await uni.showModal({
			// 		title:'提示',
			// 		content:'确认退出登录吗？'
			// 	}).catch(err => err)
				
			// 	if (res && res.confirm) {
			// 		console.log('用户点击了确定')
			// 		//清空数据
			// 		this.updateAddress({})
			// 		this.updateUserinfo({})
			// 		this.updateToken('')
			// 	}else if (res.cancel) {
			// 		console.log('用户点击了取消')
			// 	}
			
			logout(){
				// let a = this;
				//退出登录 退出成功后 清空保存在本地的信息(token userinfo address)
				uni.showModal({
					title:'提示',
					content:'确认退出登录吗？',
					confirmText:'确认',
					cancelText: '取消',
					success: (res)=> {
						if (res.confirm) {
							console.log('用户点击了确定')
							//清空数据
							this.updateAddress({})
							this.updateUserinfo({})
							this.updateToken('')
						}else if (res.cancel) {
							console.log('用户点击了取消')
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.my-userinfo-container{
		height: 100%;
		background-color: #F4F4F4;
		.top-box{
			height: 400rpx;
			background-color: #C00000;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			.avatar{
				width: 90px;
				height: 90px;
				border-radius: 45px;
				border: 2px solid #fff;
				box-shadow: 0 0 2px 2px black;
			}
			.nickname {
				color: #FFF;
				font-size: 16px;
				font-weight: bold;
				margin-top: 10px;
			}
		}
		.panel-list{
			padding: 0 10px;
			// top: -10px;
			// position: relative;
			transform: translateY(-5%);
			.panel{
				background-color: white;
				border-radius: 5px;
				margin-bottom: 8px;
				.panel-title{
					padding-left: 10px;
					border-bottom: 1px solid #f4f4f4;
					line-height: 45px;
				}
				.panel-body{
					display: flex;
					justify-content: space-around;
					font-size: 15px;
					.panel-item{
						display: flex;
						align-items: center;
						flex-direction: column;
						font-size: 15px;
						padding: 10px 0;
						.icon{
							width: 35px;
							height: 35px;
							margin-bottom: 5px;
						}
					}
				}
				.panel-list-item{
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 1px solid #f4f4f4;
					padding: 0 10px;
					height: 45px;
				}
			}
		}
	}
</style>
